package com.zh.repo.util;

import com.zh.repo.entity.vo.BakeOvenInfo;
import com.zh.repo.entity.vo.BakeOvenInfoView;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @description:
 * @author:
 * @time: 2025-05-11 16:30
 * @version: 1.0
 */
@Component
public class CalendarUtil {

    //依据所传年份+月份，列出月份的每一天
    public static List<String> getDayListOfMonth(){
        List<String>list=new ArrayList<>();
        Calendar aCalendar=Calendar.getInstance(Locale.CHINA);
        int year=aCalendar.get(Calendar.YEAR);
        int month=aCalendar.get(Calendar.MONTH)+1;
        int day=aCalendar.getActualMaximum(Calendar.DATE);
        for(int i=1;i<=day;i++){
            String aDate=String.valueOf(year)+"-"+month+"-"+i;
            list.add(aDate);
        }
        return list;
    }

    public static List<String> getDayListOfMonth(String strDate) throws ParseException {
        List<String>list=new ArrayList<>();
        Calendar aCalendar=Calendar.getInstance(Locale.CHINA);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date cusDate=sdf.parse(strDate);
        //Date转Calendar
        aCalendar.setTime(cusDate);
        int year=aCalendar.get(Calendar.YEAR);
        int month=aCalendar.get(Calendar.MONTH)+1;
        int day=aCalendar.getActualMaximum(Calendar.DATE);
        for(int i=1;i<=day;i++){
            String aDate=String.valueOf(year)+"-"+month+"-"+i;
            list.add(aDate);
        }
        return list;
    }
    //1.创建烘箱信息对象，除日期外，其他值暂时为空
    public static List<BakeOvenInfo> getDayListOfMonthToBakeOven(String strDate) throws ParseException {
        List<BakeOvenInfo>bakeOvenInfoList=new ArrayList<>();
        Calendar aCalendar=Calendar.getInstance(Locale.CHINA);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        if(strDate.length()==7){
            strDate=strDate+"-01";
        }
        Date cusDate=sdf.parse(strDate);
        //Date转Calendar
        aCalendar.setTime(cusDate);
        int year=aCalendar.get(Calendar.YEAR);
        int month=aCalendar.get(Calendar.MONTH)+1;
        int day=aCalendar.getActualMaximum(Calendar.DATE);
        for(int i=1;i<=day;i++){
            String aDate=String.valueOf(year)+"-"+month+"-"+i;
            BakeOvenInfo bakeOvenInfo=new BakeOvenInfo();
            bakeOvenInfo.setKsrq(aDate);
            bakeOvenInfoList.add(bakeOvenInfo);
        }
        return bakeOvenInfoList;
    }
    //2.依据日期查询出来的烘箱信息对象A--再把相同日期条件查询后的烘箱对象B值，更新A中的信息
    //A需显示：测试人员+开始/结束日期~烘箱号、测试要求

    public static List<BakeOvenInfoView> getDayListOfMonthToBakeOvenInfoView(String strDate) throws ParseException {
        List<BakeOvenInfoView>bakeOvenInfoList=new ArrayList<>();
        Calendar aCalendar=Calendar.getInstance(Locale.CHINA);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        if(strDate.length()==7){
            strDate=strDate+"-01";
        }
        Date cusDate=sdf.parse(strDate);
        //Date转Calendar
        aCalendar.setTime(cusDate);
        int year=aCalendar.get(Calendar.YEAR);
        int month=aCalendar.get(Calendar.MONTH)+1;
        int day=aCalendar.getActualMaximum(Calendar.DATE);
        for(int i=1;i<=day;i++){
            String aDate=String.valueOf(year)+"-"+month+"-"+i;
            BakeOvenInfoView bakeOvenInfo=new BakeOvenInfoView();
            bakeOvenInfo.setKsrq(aDate);
            bakeOvenInfoList.add(bakeOvenInfo);
        }
        return bakeOvenInfoList;
    }
}
